﻿MPT.addAction("upper_u_info", function(_elm) {
    var avatar_jQ = $('.e_avatar', _elm);
    var nickname_jQ = $('.e_nickname', _elm);
    var area_jQ = $('.e_area', _elm);
    var level_jQ = $('.e_level', _elm);
    var mysign_jQ = $('.e_mysign', _elm);
    var friend_show_jQ = $('.e_friend_show', _elm);
    var nofriend_hide_jQ = $('.e_nofriend_hide', _elm);
    var add_gz_jQ = $('.e_add_gz', _elm);
    var add_hy_jQ = $('.e_add_hy', _elm);

    var hy_jQ = $('.e_hy', _elm);
    var fs_jQ = $('.e_fs', _elm);
    var fy_jQ = $('.e_fy', _elm);
    var sex_jQ = $('.e_sex', _elm);
    var city_jQ = $('.e_city', _elm);
    var home_jQ = $('.e_home', _elm);

    var userID = Util.GetHashParam();



    var data = {"targetId": userID};
    SiteUtil.getRegion(function() {console.log()});
    Backend.findOtherUserInfo(data, function(_resp) {
    if (Backend.resultValidate(_resp)) {
        var result = _resp.data;
        var nickname = result.nickname;
        var avatarPath = Util.avatarPath(userID);
        var area = result.area;
        var grade = Util.transformGradeToIcon(result.grade);
        var mysign = Util.truncName(result.signature, 30);
        var hyNub = result.fansNum;
        var fsNub = result.fansNum;
        //初始化地区
        var homeCity = '未填写';
        var liveCity = '未填写';
        if (result.hometownCityId) {
          if (province_city_map.city[result.hometownCityId])
              homeCity = province_city_map.city[result.hometownCityId].name;
          if (province_city_map.city[result.liveCityId])
              liveCity = province_city_map.city[result.liveCityId].name;
        }

        avatar_jQ.attr('src',avatarPath);
        nickname_jQ.html(nickname);
        area_jQ.html(area);
        level_jQ.html(grade);
        mysign_jQ.html(mysign == null || mysign == "" ? "TA还没有签名" : mysign); //todo:无签名
        fs_jQ.html(fsNub);

        if(result.isFriend){
            friend_show_jQ.show();
            nofriend_hide_jQ.hide();


            sex_jQ.html(result.sex);
            city_jQ.html(liveCity);
            home_jQ.html(homeCity);
        }else{
            friend_show_jQ.hide();
            nofriend_hide_jQ.show();
            
            add_hy_jQ.show();//按钮
        }
        if(result.isFollowed){
            add_gz_jQ.find('strong').html('取消关注').attr('title','取消关注');
        }
        add_gz_jQ.click(function(){
            if(result.isFollowed){
                add_gz_jQ.find('strong').html('加关注').attr('title','加关注');
            }else{
                add_gz_jQ.find('strong').html('取消关注').attr('title','取消关注');
            }
        })

    } else {
        Tip.show("用户信息加载错误");
    }
    }, function() {
        Tip.show("用户信息加载错误");
    });


});